from django.db import models

# Create your models here.
from users.models import Ops_user


class Alarm_info(models.Model):
    is_handle_choices = (
        (0, '已处理'),
        (1, '未处理')
    )
    is_ignore_choices = (
        (0, '已忽略'),
        (1, '未忽略')
    )

    alarm_name = models.CharField(max_length=32, verbose_name='报警名称')
    alarm_info = models.TextField(verbose_name='报警内容')
    alarm_time = models.DateTimeField(auto_now=True, verbose_name='报警时间')
    edit_user = models.ForeignKey(to=Ops_user, on_delete=models.DO_NOTHING, null=True, blank=True, verbose_name='操作用户',
                                  db_constraint=False)
    is_handle = models.SmallIntegerField(choices=is_handle_choices, default=1, verbose_name='处理状态')
    is_ignore = models.SmallIntegerField(choices=is_ignore_choices, default=1, verbose_name='忽略状态')

    def edit_user_name(self):
        return self.edit_user.username

    def is_handle_name(self):
        return self.get_is_handle_display()

    def is_ignore_name(self):
        return self.get_is_ignore_display()

    class Meta:
        db_table = 'ops_alarm_info'
        verbose_name = '主机表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.alarm_name

